package com.songlanyun.modules.rabbitmq.mq.consumer;

import com.rabbitmq.client.Channel;
import com.songlanyun.common.utils.custom.ClassConvertUtils;
import com.songlanyun.modules.gains.service.ShopOrderGainsService;
import com.songlanyun.modules.order.entity.Order;
import com.songlanyun.modules.order.service.OrderService;
import com.songlanyun.modules.rabbitmq.MqConstant;
import com.songlanyun.modules.rabbitmq.service.SendMsgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@Slf4j
public class ShopGainsComputeConsumer extends BaseConsumer{

    @Autowired
    private OrderService orderService;

    @Autowired
    private ShopOrderGainsService shopOrderGainsService;

    @Autowired
    private SendMsgService sendMsgService;




    @Override
    protected void process(Message message) {
        Long orderId = ClassConvertUtils.objToLong(new String(message.getBody()));
        Order order = orderService.getById(orderId);
        /** 因为安全期间,计算商家与会员分润所得移至订单支付成功之处，因为一旦MQ出现问题无法往回
        if(!order.getExchange())
        {
            shopOrderGainsService.initCreate(order);
        }
        */
        /**
         * 发送订单支付成功后的处理消息主要是用来做会员升级
         */
//        sendMsgService.send(MqConstant.UserUpgradeConstant.USER_UPGRADE_EXCHANGE, MqConstant.UserUpgradeConstant.USER_UPGRADE_ROUTER
//                , order.getId().toString());

    }

    @RabbitListener(queues = MqConstant.ComputeShopGainsConstant.COMPUTE_SHOP_GAINS_QUEUE)
    public void consume(Message message, Channel channel) throws IOException {
        super.handle(message,channel);
    }
}
